﻿using System.Configuration;
using StructureMap;
using System.Collections.Generic;
using App.Utility;
using App.Account;
using System.Linq;
using System.Web;


namespace App
{
    public static class Bootstrapper
    {
        public static void ConfigurePlugins()
        {
            ConfigureMap();

            string ServiceLocation = ConfigurationSettings.AppSettings["ServiceLocation"];

            IList<IPluggable> plugins = ObjectFactory.GetAllInstances<IPluggable>();
            foreach(IPluggable plugin in plugins)
                plugin.ConfigurePlugin(ServiceLocation);
        }

        public static void InitPlugins(HttpApplication App)
        {
            ConfigureMap();

            IList<IPluggable> plugins = ObjectFactory.GetAllInstances<IPluggable>();
            foreach (IPluggable plugin in plugins)
                plugin.InitPlugin(App);
        }

        private static void ConfigureMap()
        {
            // needs to be in structuremap.config
            ObjectFactory.Configure(x =>
            {
                x.ForRequestedType<IPluggable>().AddConcreteType<App.Account.Plugin>();
            });
        }
    }


}
